import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:photo_view/photo_view.dart';
import 'package:photo_view/photo_view_gallery.dart';


class goodsPhotoGalleryPage extends StatefulWidget {
  goodsPhotoGalleryPage(this.galleryItems, {this.currentIndex = 0});
  final List<String> galleryItems;
  var currentIndex = 0;
  @override
  _PhotoGalleryPageState createState() => _PhotoGalleryPageState();
}

class _PhotoGalleryPageState extends State<goodsPhotoGalleryPage> {
  PageController pageController;
  @override
  void initState() {
    super.initState();
    pageController = PageController(initialPage: widget.currentIndex);
    _currentIndex= widget.currentIndex+1;
  }
int _currentIndex= 1;
  @override
  Widget build(BuildContext context) {
    return
      Container(
       // decoration: widget.backgroundDecoration,
        constraints: BoxConstraints.expand(
        height: MediaQuery.of(context).size.height,
          width: MediaQuery.of(context).size.width,
    ),
    child:


      Stack(
       //  fit: StackFit.expand,
        alignment: AlignmentDirectional.topCenter ,
          children:[

      Container(
        child: PhotoViewGallery.builder(
          scrollPhysics: const BouncingScrollPhysics(),
          builder: (BuildContext context, int index) {
            return PhotoViewGalleryPageOptions(
              onTapUp: (context, detail, value) {
                Get.back();
              },
              imageProvider: NetworkImage(widget.galleryItems[index]),
              initialScale: PhotoViewComputedScale.contained ,
              heroAttributes: PhotoViewHeroAttributes(tag: index),
            );
          },
          itemCount: widget.galleryItems.length,
          loadingBuilder: (context, event) => Center(
            child: Container(
              width: 20.0,
              height: 20.0,
              child: CircularProgressIndicator(
                value: event == null
                    ? 0
                    : event.cumulativeBytesLoaded / event.expectedTotalBytes,
              ),
            ),
          ),
          // backgroundDecoration: widget.backgroundDecoration,
          pageController: pageController,
           onPageChanged: onPageChanged,
        ),

    ),
            Container(
                padding: const EdgeInsets.all(30.0),
                child: Text('$_currentIndex/${widget.galleryItems.length}',
                    style:TextStyle(color:Colors.white,fontSize: 16 )
                )),
    ]

)
      )
    ;
  }
  void onPageChanged(int index) {
    setState(() {
      _currentIndex = index+1;
    });
  }
}
